CFLAGS = -Wall -fprofile-arcs -ftest-coverage -fpic -coverage -lm -std=gnu99
CC = gcc

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testBuyCard.c dominion.o rngs.o
	gcc -o testBuyCard -g  testBuyCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
	gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

player: player.c interface.o
	gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)

unittest1: dominion.o dominion_helpers.h dominion.h
	gcc -o ut1 unittest1.c dominion.o rngs.o $(CFLAGS)

unittest2: dominion.o dominion_helpers.h dominion.h
	gcc -o ut2 unittest2.c dominion.o rngs.o $(CFLAGS)

unittest3: dominion.o dominion_helpers.h dominion.h
	gcc -o ut3 unittest3.c dominion.o rngs.o $(CFLAGS)

unittest4: dominion.o dominion_helpers.h dominion.h
	gcc -o ut4 unittest4.c dominion.o rngs.o $(CFLAGS)

cardtest1: dominion.o dominion_helpers.h dominion.h
	gcc -o ct1 cardtest1.c dominion.o rngs.o $(CFLAGS)

cardtest2: dominion.o dominion_helpers.h dominion.h
	gcc -o ct2 cardtest2.c dominion.o rngs.o $(CFLAGS)

cardtest3: dominion.o dominion_helpers.h dominion.h
	gcc -o ct3 cardtest3.c dominion.o rngs.o $(CFLAGS)

cardtest4: dominion.o dominion_helpers.h dominion.h
	gcc -o ct4 cardtest4.c dominion.o rngs.o $(CFLAGS)

tests: unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4

unittestresults.out: tests
	-./ut1 > unittestresults.out
	-./ut2 >> unittestresults.out
	-./ut3 >> unittestresults.out
	-./ut4 >> unittestresults.out
	-./ct1 >> unittestresults.out
	-./ct2 >> unittestresults.out
	-./ct3 >> unittestresults.out
	-./ct4 >> unittestresults.out
	-gcov -b ./unittest1.c  >> unittestresults.out
	-gcov -b ./unittest2.c  >> unittestresults.out
	-gcov -b ./unittest3.c  >> unittestresults.out
	-gcov -b ./unittest4.c  >> unittestresults.out
	-gcov -b ./cardtest1.c  >> unittestresults.out
	-gcov -b ./cardtest2.c  >> unittestresults.out
	-gcov -b ./cardtest3.c  >> unittestresults.out
	-gcov -b ./cardtest4.c dominion.c >> unittestresults.out

randomtestcard.out: randomtestcard
	-./randomtestcard > randomtestcard.out
	-gcov -b -f dominion.c >> randomtestcard.out

randomtestadventurer.out: randomtestadventurer
	-./randomtestadventurer > randomtestadventurer.out
	-gcov -b -f randomtestadventurer.c >> randomtestadventurer.out


randomtestcard: randomtestcard.c showGameState.o showGameState.o dominion.o mySeaHag.o
	gcc -o randomtestcard  randomtestcard.c  showGameState.o dominion.o mySeaHag.o rngs.o -lgsl -lgslcblas -lm -g $(CFLAGS)

randomtestadventurer: randomtestadventurer.c showGameState.o showGameState.o dominion.o myAdventurerCard.o
	gcc -o randomtestadventurer  randomtestadventurer.c  showGameState.o dominion.o myAdventurerCard.o rngs.o -lgsl -lgslcblas -lm -g $(CFLAGS)

showGameState.o: showGameState.h showGameState.c 
	gcc -c showGameState.c -g  $(CFLAGS)

mySeaHag.o: mySeaHag.h mySeaHag.c 
	gcc -c mySeaHag.c -g  -lgsl -lgslcblas -lm $(CFLAGS)

myAdventurerCard.o: myAdventurerCard.h myAdventurerCard.c 
	gcc -c myAdventurerCard.c -g  -lgsl -lgslcblas -lm $(CFLAGS)		

all: playdom player testDrawCard testBuyCard badTestDrawCard 

clean:
	rm -f *.o playdom.exe playdom test.exe test player player.exe 
	rm -f testDrawCard testDrawCard.exe testBuyCard testBuyCard.exe randomtestcard randomtestadventurer rt
	rm -f badTestDrawCard badTestDrawCard.exe *.gcov *.gcda *.gcno *.so
	rm -f ut? ct?
